
<h1><span class="yiyi-st" id="yiyi-12">numpy.around</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.around.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.around.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.around"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">around</code><span class="sig-paren">(</span><em>a</em>, <em>decimals=0</em>, <em>out=None</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/core/fromnumeric.py#L2752-L2822"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">均匀到给定的小数位数。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-15">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-16"><strong>a</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-17">输入数据。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-18"><strong>小数</strong>：int，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-19">舍入的小数位数（默认值：0）。</span><span class="yiyi-st" id="yiyi-20">如果小数是负数，它指定小数点左边的位置数。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-21"><strong>out</strong>：ndarray，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-22">用于放置结果的替代输出数组。</span><span class="yiyi-st" id="yiyi-23">它必须具有与预期输出相同的形状，但如果必要，将输出输出值的类型。</span><span class="yiyi-st" id="yiyi-24">有关详细信息，请参见<code class="xref py py-obj docutils literal"><span class="pre">doc.ufuncs</span></code>（“输出参数”部分）。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-25">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-26"><strong>rounded_array</strong>：ndarray</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-27">与<em class="xref py py-obj">a</em>类型相同的数组，包含四舍五入值。</span><span class="yiyi-st" id="yiyi-28">除非指定了<em class="xref py py-obj">out</em>，否则将创建一个新的数组。</span><span class="yiyi-st" id="yiyi-29">将返回对结果的引用。</span></p>
<p><span class="yiyi-st" id="yiyi-30">复数的实部和虚部分别进行四舍五入。</span><span class="yiyi-st" id="yiyi-31">舍入浮点的结果是浮点数。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-32">也可以看看</span></p>
<dl class="docutils">
<dt><span class="yiyi-st" id="yiyi-33"><a class="reference internal" href="numpy.ndarray.round.html#numpy.ndarray.round" title="numpy.ndarray.round"><code class="xref py py-obj docutils literal"><span class="pre">ndarray.round</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-34">等效法</span></dd>
</dl>
<p class="last"><span class="yiyi-st" id="yiyi-35"><a class="reference internal" href="numpy.ceil.html#numpy.ceil" title="numpy.ceil"><code class="xref py py-obj docutils literal"><span class="pre">ceil</span></code></a>，<a class="reference internal" href="numpy.fix.html#numpy.fix" title="numpy.fix"><code class="xref py py-obj docutils literal"><span class="pre">fix</span></code></a>，<a class="reference internal" href="numpy.floor.html#numpy.floor" title="numpy.floor"><code class="xref py py-obj docutils literal"><span class="pre">floor</span></code></a>，<a class="reference internal" href="numpy.rint.html#numpy.rint" title="numpy.rint"><code class="xref py py-obj docutils literal"><span class="pre">rint</span></code></a>，<a class="reference internal" href="numpy.trunc.html#numpy.trunc" title="numpy.trunc"><code class="xref py py-obj docutils literal"><span class="pre">trunc</span></code></a></span></p>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-36">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-37">对于精确到十进制值之间一半的值，Numpy舍入到最接近的偶数值。</span><span class="yiyi-st" id="yiyi-38">因此1.5和2.5圆到2.0，-0.5和0.5圆到0.0，等等。</span><span class="yiyi-st" id="yiyi-39">结果也可能是令人惊讶的，因为在IEEE浮点标准<a class="reference internal" href="#r9" id="id1">[R9]</a>中的十进制小数的不精确表示以及当以十的幂定标时引入的误差。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-40">参考文献</span></p>
<table class="docutils citation" frame="void" id="r9" rules="none">
<colgroup><col class="label"><col></colgroup>
<tbody valign="top">
<tr><td class="label"><span class="yiyi-st" id="yiyi-41">[R9]</span></td><td><span class="yiyi-st" id="yiyi-42"><em>（<a class="fn-backref" href="#id1">1</a>，<a class="fn-backref" href="#id2">2</a>）</em>“关于IEEE 754状态的演讲”，William Kahan，<a class="reference external" href="http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF">http：//www.cs .berkeley.edu /〜wkahan / ieee754status / IEEE 754.PDF</a></span></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="r10" rules="none">
<colgroup><col class="label"><col></colgroup>
<tbody valign="top">
<tr><td class="label"><span class="yiyi-st" id="yiyi-43"><a class="fn-backref" href="#id3">[R10]</a></span></td><td><span class="yiyi-st" id="yiyi-44">“How unile are Mindless Assessments of Roundoff in Floating-Point Computation？”，William Kahan，<a class="reference external" href="http://www.cs.berkeley.edu/~wkahan/Mindless.pdf">http://www.cs.berkeley.edu/~wkahan/Mindless.pdf</a></span></td></tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-45">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">([</span><span class="mf">0.37</span><span class="p">,</span> <span class="mf">1.64</span><span class="p">])</span>
<span class="go">array([ 0.,  2.])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">([</span><span class="mf">0.37</span><span class="p">,</span> <span class="mf">1.64</span><span class="p">],</span> <span class="n">decimals</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">array([ 0.4,  1.6])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">([</span><span class="o">.</span><span class="mi">5</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">,</span> <span class="mf">3.5</span><span class="p">,</span> <span class="mf">4.5</span><span class="p">])</span> <span class="c1"># rounds to nearest even value</span>
<span class="go">array([ 0.,  2.,  2.,  4.,  4.])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">11</span><span class="p">],</span> <span class="n">decimals</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="c1"># ndarray of ints is returned</span>
<span class="go">array([ 1,  2,  3, 11])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">11</span><span class="p">],</span> <span class="n">decimals</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">array([ 0,  0,  0, 10])</span>
</pre></div>
</div>
</dd></dl>
